/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.news;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Date;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import po.News;
import po.User;
import service.NewsService;
import service.OrgService;

/**
 *
 * @author sony
 */
public class SubmitEditNewsAction extends ActionSupport implements ServletRequestAware{

    private NewsService newsService;
    private HttpServletRequest request;
    private String title;
    private String content;

    @Override
    public String execute() {
        if (ActionContext.getContext().getSession().get("user") == null) {
            return ERROR;
        } else {
            User usr = (User) ActionContext.getContext().getSession().get("user");
            int newsId = Integer.parseInt(request.getParameter("newsId"));
            if(!newsService.isAuthor(newsId,usr.getId())){
                return ERROR;
            }else{
                News newNews = newsService.getNews(newsId);
                newNews.setCotent(content);
            
                newNews.setTitle(title);
                newsService.updateNews(newNews);
         
            }
        }
        return SUCCESS;
    }

    public NewsService getNewsService() {
        return newsService;
    }

    public void setNewsService(NewsService newsService) {
        this.newsService = newsService;
    }

 

    public void setServletRequest(HttpServletRequest arg0) {
        this.request=arg0;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

}

